//
//  BaseNavigationController.m
//  WXWeibo
//
//  Created by apple on 16/5/9.
//  Copyright © 2016年 zic_magic. All rights reserved.
//

#import "BaseNavigationController.h"
#import "ThemeImageView.h"
#import "ThemeManager.h"
#import "ThemeButton.h"
@interface BaseNavigationController ()

@end

@implementation BaseNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
    [self.navigationBar setShadowImage:[[UIImage alloc] init]];
    
    
//    [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"mask_titlebar64@2x.png"] forBarMetrics:UIBarMetricsDefault];
    [self themeChangeAction];
    
    
    UIColor *titleColor = [[ThemeManager shareManager] themeColorWithColorName:@"Mask_Title_color"];
    
    NSDictionary *dic = @{
                          NSFontAttributeName : [UIFont boldSystemFontOfSize:22],
                          NSForegroundColorAttributeName : titleColor
                          };
    [self.navigationBar setTitleTextAttributes:dic];
    
    self.navigationBar.translucent = NO;
    
}


- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    
    if (self) {
        
        [self _observeThemeChangeNotification];
        
    }
    
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    
    
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self _observeThemeChangeNotification];
    }
    return self;
}

- (void)_observeThemeChangeNotification {
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeChangeAction) name:kThemeChangeNotification object:nil];
    
}

- (void)themeChangeAction {
    
    UIImage *backImg = [[ThemeManager shareManager] themeImageWithImageName:@"mask_titlebar64@2x.png"];
    [self.navigationBar setBackgroundImage:backImg forBarMetrics:UIBarMetricsDefault];
}

- (void)dealloc {
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:kThemeChangeNotification object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    
    return  UIStatusBarStyleLightContent;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
    [super pushViewController:viewController animated:animated];
    
    
        ThemeButton *backButton = [ThemeButton buttonWithType:UIButtonTypeCustom];
        
        backButton.frame = CGRectMake(0, 0, 64, 44);
        backButton.backgroundImageName = @"titlebar_button_back_9";
        
        
        backButton.titleLabel.font = [UIFont systemFontOfSize:12];
        [backButton setTitle:@"返回" forState:UIControlStateNormal];
    
    [backButton addTarget:self action:@selector(popAction) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
        viewController.navigationItem.leftBarButtonItem = leftItem;
    
    
}

- (void)popAction {
    
    [self popToRootViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
